import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.HTML.Tag;

public class dblpEngine extends IProvider {
	public dblpEngine(BotConfig cfg){
		super(cfg);
		_posCntSD = new SearchDetails(".*Hits ([0-9]+) - ([0-9]+) of ([0-9]+) .*",
				3, null, Tag.DIV);
	}
	
	private SearchDetails _posCntSD = null;
	@Override
	protected SearchDetails getPositionCountSearch(){
		return _posCntSD;
	}
	
	@Override
	protected String getEnginName() {
		return "dblp";
	}
	@Override
	protected String getSearchURL(int Year, String useCase, String categ) {
		//String patUrl ="http://dblp.mpi-inf.mpg.de/autocomplete-php/autocomplete/ajax.php?query=year%3A";		
		//patUrl += Integer.toString(Year) + "%20";
		//patUrl += useCase.replace('+', ' ').replace("+", "%20") + "%20";
		//patUrl += categ.replace('+', ' ').replace("+", "%20");
		//patUrl += "&name=dblp&path=/dblp/&page=index.php&log=/var/opt/completesearch/log/completesearch.error_log&qid=10&navigation_mode=user&language=en&mcsr=40&mcc=0&mcl=80&hpp=8&eph=3&er=7&dm=3&bnm=R&ll=2&mo=100&syn=0&deb=0&hrd=1a&hrw=1d&qi=1&fh=1&fhs=1&mcs=8&&rid=";
		//patUrl += Integer.toString(rid++);
		String patUrl = "http://dblp.mpi-inf.mpg.de/dblp/index.php?query=year:";
		patUrl += Integer.toString(Year) + "%20";
		if(useCase.length() > 0)
		{
			if(useCase.indexOf('|') >= 0)
				patUrl += useCase.substring(0, useCase.indexOf('|')).replace("|", "") + "%20";
			else
				patUrl += useCase.replace(' ', '+').replace("+", "%20") + "%20";
		}
		patUrl += categ.replace(' ', '+').replace("+", "%20");		
		return patUrl;
		//return "http://dblp.mpi-inf.mpg.de/dblp/index.php?query=data+mining";
	}
	
	protected int finalTest(HTMLDocument htmlDoc)
	{
		try
		{
			String cont = htmlDoc.getText(0, htmlDoc.getLength());
			if(cont.contains("single hit"))
				return 1;
		}
		catch (Exception e) {
		}
		return 0;
	}
	@Override
	protected String getURL(String extUrl){
		return extUrl;
	}
	
	@Override
	protected SearchDetails getKeySearchDetails(int idx) {
		return null;
	}
	@Override
	protected int getKeyWordCount() {
		return 0;
	}
	@Override
	protected String getKeyWordName(int idx) {
		return null;
	}
}
